// 美化react源代码

const prettier = require("prettier");
const fs = require("fs");
const path = require("path");

let [env = "--dev"] = process.argv.slice(2);
env = env.slice(2);

const folderPath = path.join(__dirname, "../modules");

fs.readdir(folderPath, (err, files) => {
  if (err) {
    console.error("Error reading folder:", err);
    return;
  }

  files.forEach((file) => {
    const filePath = path.join(folderPath, file);

    fs.readFile(filePath, async (err, code) => {
      const bcode = await prettier.format(code.toString(), {
        tabWidth: 2,
        singleQuote: true,
        jsxSingleQuote: true,
        trailingComma: "none",
        bracketSameLine: true,
        semi: false,
        parser: "babel",
      });
      fs.writeFile(filePath, bcode, {}, (err) => {
        if (err) {
          console.error(err, "error occus, in writing beautify code.");
        }
      });
    });
  });
});
